package com.example.demo.messageWall.controller;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RequestMapping("/user")
@RestController
public class LoginController {
    @RequestMapping("/login")
    public Boolean login(String userName, String password, HttpSession session){
//        if(userName == null || userName.length() == 0 ||
//                password == null || password.length() == 0){
//            return false;
//        }
        if(!StringUtils.hasLength(userName) || !StringUtils.hasLength(password)){
            return false;
        }
        if("admin".equals(userName) && "123".equals(password)){
            session.setAttribute("username", "admin");
            return true;
        }
        return false;
    }
    @RequestMapping("/getInfo")
    public String getInfo(HttpSession session){
        String userName = (String) session.getAttribute("username");
        return userName;
    }
}
